//排序加二分查找
let nums = [24,3,82,22,35,84,19]
var triangleNumber = function(nums) {
    nums.sort((a,b)=>a-b)
    let ans = 0;
    for(let i=0;i<nums.length-2;i++){
        for(let j=i+1;j<nums.length-1;j++){
            let left = j+1
            let right = nums.length-1
            let k = j
            while(left<=right){
                let mid = Math.floor((left+right)/2)
                if(nums[mid]>=(nums[i]+nums[j])){
                    right = mid - 1
                }else{
                    left = mid+1
                    k=mid 
                }
            }
            ans = ans +k-j
        }
    }   
    return ans
}
console.log(triangleNumber(nums));


